package com.example.demo.Context;

import com.example.demo.Configure.BeanTools;
import com.example.demo.Service.MyHandler;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class MyContext {
    Map<String,Class> map=new HashMap<>();

    public MyContext(Map<String, Class> map) {
        this.map = map;
    }

    public MyHandler getInstance(String type){
        Class clazz  = map.get(type);
        if(StringUtils.isEmpty(clazz)){
            throw new IllegalArgumentException("class of this type is null");
        }
        return (MyHandler) BeanTools.getBean(clazz);
    }
}
